<template>
	<view class="container">
		<view class="box box-bg">
			<view class="box_module">
				<view class="box_module-item" v-for="(item, index) in moduleData" :key="item.id" @tap="toDetail(index)">
					<view class="icon">
						<image :src="item.icon"></image>
					</view>
					<view class="text">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>
		<!-- 接入情况 -->
		<view class="box">
			<view class="box_title">
				<image :src="connectImg"></image>
				<view class="box_name">
					<!-- <image :src="connectImg"></image> -->
					接入情况</view>
			</view>
			<view class="box_access">
				<view class="box_access-item">
					<view class="num">1</view>
					<view class="text">站所数</view>
				</view>
				<view class="box_access-item">
					<view class="num">30</view>
					<view class="text">视频监控</view>
				</view>
				<view class="box_access-item">
					<view class="num">4</view>
					<view class="text">环境监控</view>
				</view>
				<view class="box_access-item">
					<view class="num">3</view>
					<view class="text">动力监控</view>
				</view>
				<view class="box_access-item">
					<view class="num">26</view>
					<view class="text">安全防范</view>
				</view>
				<view class="box_access-item">
					<view class="num">47</view>
					<view class="text">火灾报警</view>
				</view>
				<view class="box_access-item">
					<view class="num">11</view>
					<view class="text">辅助控制</view>
				</view>
				<view class="box_access-item">
					<view class="num">6</view>
					<view class="text">在线监测</view>
				</view>
			</view>
		</view>
		<!-- 事件记录 -->
		<view class="box ">
			<view class="box_title">
				<image :src="eventRecordImg"></image>
				<view class="box_name">事件记录</view>
			</view>
			<view class="box_record">
				<view class="total">
					<!-- 离线 -->
					<view class="total-item offline">
						<view class="left">
							<image :src="offlineIcon"></image>
							<text class="label value">离线</text>
						</view>
						<view class="right">
							<view class="right-item">
								<text class="value">2</text>
								<text class="name">接入</text>
							</view>
							<view class="right-item">
								<text class="value">1</text>
								<text class="name">在线</text>
							</view>
							<view class="right-item">
								<text class="value">0</text>
								<text class="name">离线</text>
							</view>
						</view>
					</view>
					<!-- 告警 -->
					<view class="total-item warning">
						<view class="left">
							<image :src="warningIcon"></image>
							<text class="label value">告警</text>
						</view>
						<view class="right">
							<view class="right-item">
								<p class="value">1</p>
								<p class="name">今日</p>
							</view>
							<view class="right-item">
								<text class="value">2</text>
								<text class="name">昨日</text>
							</view>
							<view class="right-item">
								<text class="value">10</text>
								<text class="name">当月</text>
							</view>
							<view class="right-item">
								<text class="value arrPosition">+14%</text>
								<text class="name">月环比</text>
								<image :src="arrowIcon"></image>
							</view>
						</view>
					</view>
				</view>
				<!-- 告警记录列表 -->
				<view class="record-list">
					<mark-slide-list :list="warningList" @click="clickMethod" @change="changeMethod"></mark-slide-list>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import markSlideList from '../../components/mark-slide-list/mark-slide-list.vue'
	export default {
		components: {
			markSlideList
		},
		name: 'slide-list',
		data() {
			return {
				moduleData: [{
						id: 1,
						name: '环境监测',
						icon: require('@/static/image/index/environmental-monitoring.png')
					},
					{
						id: 2,
						name: '动力监测',
						icon: require('@/static/image/index/dynamic-monitoring.png')
					},
					{
						id: 3,
						name: '安全防范',
						icon: require('@/static/image/index/safety-defense.png')
					},
					{
						id: 4,
						name: '火灾报警',
						icon: require('@/static/image/index/fire-alert.png')
					},
					{
						id: 5,
						name: '辅助控制',
						icon: require('@/static/image/index/minor-control.png')
					},
					{
						id: 6,
						name: '在线监测',
						icon: require('@/static/image/index/online-monitoring.png')
					},
					{
						id: 7,
						name: '视频监控',
						icon: require('@/static/image/index/vedio-monitoring.png')
					},
					{
						id: 8,
						name: '电子地图',
						icon: require('@/static/image/index/Emap.png')
					}
				],
				warningList: [{
						id: 1,
						time: '2020-10-31 18:00:11',
						name: '温度1',
						desc: '超上限',
						percentage: '21℃',
						slide_x: 0,
						isConfirm: 0
					},
					{
						id: 2,
						time: '2020-10-31 18:00:11',
						name: '温度1',
						desc: '超上限',
						percentage: '21℃',
						slide_x: 0,
						isConfirm: 1
					}
				],
				unConfirmed: true,
				confirmed: true,
				connectImg: '../../static/image/index/connect-situation.png',
				eventRecordImg: '../../static/image/index/event-record.png',
				offlineIcon: '../../static/image/index/offline.png',
				warningIcon: '../../static/image/index/warning.png',
				notConfirmIcon: '../../static/image/index/notConfirm.png',
				confirmIcon: '../../static/image/index/confirmed.png',
				arrowIcon: '../../static/image/index/arrow.png',
				deleteIcon: '../../static/image/index/delete-icon.png'
			}
		},

		methods: {
			// 跳转至具体页面
			toDetail(index) {
				if(index == 0) {
					uni.navigateTo({
						url: "/pages/environment-monitor/environment-monitor"
					})
				}
				if(index == 4) {
					uni.navigateTo({
						url: "/pages/minor-control/minor-control"
					})
				}
				if(index == 6) {
					uni.navigateTo({
						url: "/pages/RVC/RVC"
					})
				}
				console.log('index', index)
			},
			/** 
			 * 点击按钮触发事件
			 * @param {Object} item 列表数据 
			 * @param {Object} buttonItem 按钮数据
			 * @param {Object} index 列表数据key
			 */
			changeMethod(data, index) {
				// console.log('滑动按钮回调', data)
				// console.log('滑动按钮回调', button)
				let self = this
				console.log('点击删除')
				// if (button.title === '删除') {
				uni.showModal({
					title: '',
					content: '确定要删除该信息吗？',
					confirmText: '删除',
					confirmColor: '#ff3b32',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定')
							self.warningList.splice(index, 1)
							uni.showToast({
								icon: "success",
								title: '操作成功!',
								duration: 2000
							});
						} else if (res.cancel) {
							console.log('用户点击取消')
						}
					}
				})
				// }
			},
			/**
			 * 点击按钮触发事件
			 * @param {Object} item 列表数据 
			 */
			clickMethod(data) {
				console.log('点击行回调', data)
			}

		}
	}
</script>

<style lang="scss" scoped>
	@import '@/common/base64/base64.scss';

	.container {
		.box {
			padding: 10rpx 24rpx;

			&.box-bg {
				background: url($index-box_module_bg) center center no-repeat;
				background-size: 100% 100%;
				border-radius: 0;
				background-position: 0 -100rpx;
			}

			.box_title {
				display: flex;
				flex-direction: row;
				height: 100rpx;
				line-height: 60rpx;
				background-image: linear-gradient(to right, #6DEDD1, #D5FFCA);
				border-radius: 10rpx;

				image {
					width: 32rpx;
					height: 32rpx;
					margin: 14rpx 10rpx 0 20rpx;
					padding-top: 4rpx;
				}

				.box_name {
					color: #fff;
					overflow: hidden;
				}
			}

			&:first-child {
				margin-top: 0;
			}

			.box_module {
				display: flex;
				flex-wrap: wrap;
				align-content: space-between;
				height: 294rpx;
				background-color: #fff;
				padding: 24rpx 0;
				border-radius: 10rpx;

				.box_module-item {
					width: 25%;
					height: 160rpx;
					text-align: center;

					.icon {
						margin: auto;
						width: 60rpx;
						height: 60rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.text {
						margin-top: 12rpx;
						font-size: 28rpx;
					}
				}
			}

			.box_name {
				color: $uni-color-primary;
				font-weight: bold;
				font-size: 28rpx;
				// margin-bottom: 30rpx;
			}

			.box_access {
				margin-top: -40rpx;
				display: flex;
				flex-wrap: wrap;
				align-content: space-between;
				height: 200rpx;
				background-color: #fff;
				border-radius: 10rpx;
				padding: 24rpx 0 40rpx;

				.box_access-item {
					width: 25%;
					height: 90rpx;
					text-align: center;

					.num {
						color: $uni-color-primary;
					}

					.text {
						margin-top: 12rpx;
						font-size: 28rpx;
					}
				}
			}

			.box_record {
				margin-top: -40rpx;
				font-size: 28rpx;
				background-color: #fff;
				border-radius: 10rpx;
				padding: 0 24rpx;
				margin-bottom: 10rpx;

				.total {
					height: 264rpx;
					padding-top: 34rpx;
					border-bottom: 1px solid #e7e7e7;

					.total-item {
						display: flex;
						flex-direction: row;
						flex: 1;
						margin-top: 10rpx;

						&:first-child {
							margin-top: 0;
						}

						.label {
							padding-right: 20rpx;
							font-weight: 550;
						}

						.name {
							color: #999999;
							padding-right: 10rpx;
						}

						.value {
							padding-right: 24rpx;
						}

						&.offline {
							.value {
								color: #666;
							}
						}

						&.warning {
							.value {
								color: #FF7547;
							}
						}

						.left {
							display: flex;
							align-items: center;
							width: 148rpx;
							font-weight: 550;

							image {
								width: 29rpx;
								height: 29rpx;
								margin-right: 7rpx;
							}
						}

						.right {
							display: flex;
							flex-direction: row;
							width: calc(100% - 148rpx);

							.right-item {
								display: flex;
								flex-direction: column;
								align-items: center;
								width: 25%;
								padding-bottom: 41rpx;

								.value {
									margin-bottom: 9rpx;
									position: relative;
								}

								image {
									width: 16rpx;
									height: 16rpx;
									position: absolute;
									right: 63rpx;
								}
							}
						}
					}
				}

				.record-list {
					margin-top: 30rpx;
					// background-color: #fff;
				}
			}
		}
	}
</style>
